package com.bwei.mypaot.base.activity;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bwei.mypaot.R;
import com.bwei.mypaot.view.Image;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingActivity;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;

import java.util.HashMap;
import java.util.Map;



/**
 * Created by Administrator on 2017/2/14.
 */

public abstract class BaseActivity extends SlidingFragmentActivity implements View.OnClickListener {
    private TextView id_tv_back;
    private TextView tv_main_title_textview;
    private TextView tv_main_title_setting;
    private ImageView iv_right_view;
    private ImageView iv_left_view;
    public Map<String, String> map;
    private SlidingMenu menu;
    private Image im;
    private LinearLayout ll_left_layout;
    //宏定义
    public static final int LEFT_IMAEG_RIGHT_IMAGE = 1;//左边图片 和右边图片
    public static final int LEFT_IMAGE_RIGHT_TEXT = 2;//左边图片,右边文字
    public static final int LEFT_IMAGE_RIGHT_NO = 3; //左边图片,右边没有
    public static final int LEFT_TEXT_RIGHT_NO = 4; //左边文字,右边没有
    public static final int LEFT_TEXT_RIGHT_IMAGE = 5; //左边文字右边图片
    public static final int LEFT_TEXT_RIGHT_TEXT = 6; //左边文字右边文字
    public static final int LEFT_NO_RIGHT_IMAGE = 7; //左边没有,右边图片
    public static final int LEFT_NO_RIGHT_TEXT = 8; //左边没有,右边文字
    public static final int LEFT_NO_RIGHT_NO = 9; //左边没有,右边没有


    //初始化头部
    public  abstract  void initHeader();
    //初始化控件
    public abstract void initWidget();

    //设置监听
    public abstract void setWidgetState();


    //定义方法来初始化控件的方法,当其他界面继承时可以实现其里边的所有方法
    public void inittHeaderWidget() {
        map = new HashMap<>();

        id_tv_back = (TextView) findViewById(R.id.id_tv_back);
        tv_main_title_textview = (TextView) findViewById(R.id.tv_main_title_textview);
        tv_main_title_setting = (TextView) findViewById(R.id.tv_main_title_setting);
        iv_right_view = (ImageView) findViewById(R.id.iv_right_view);
        iv_left_view = (ImageView) findViewById(R.id.iv_left_view);
        ll_left_layout = (LinearLayout) findViewById(R.id.ll_left_layout);
    }
//设置标题
    public void setTitle(String title){
        id_tv_back.setVisibility(View.GONE);
        tv_main_title_setting.setVisibility(View.GONE);
        iv_right_view.setVisibility(View.GONE);
        iv_left_view.setVisibility(View.GONE);
        tv_main_title_textview.setText(title);

    }
    //设置左边显示图片
    public void addImageLeftListener(View.OnClickListener listener){
        iv_left_view.setVisibility(View.VISIBLE);
        iv_left_view.setOnClickListener(listener);
    }
    //设置左边显示图片
    public void addImageLeftListener(View.OnClickListener listener,int id){
        iv_left_view.setVisibility(View.VISIBLE);
        iv_left_view.setOnClickListener(listener);
        iv_left_view.setImageResource(id);
    }
    public void addBtnLeftListener(View.OnClickListener listener){
        id_tv_back.setVisibility(View.VISIBLE);
        id_tv_back.setOnClickListener(listener);
    }
    public void addBtnLeftListener(View.OnClickListener listener,String title){
        id_tv_back.setVisibility(View.VISIBLE);
        id_tv_back.setOnClickListener(listener);
        id_tv_back.setText(title);
    }
    //设置右边显示图片
    public void addImageRightListener(View.OnClickListener listener){
        iv_right_view.setVisibility(View.VISIBLE);
        iv_right_view.setOnClickListener(listener);
    }
    //设置右边显示图片
    public void addImageRightListener(View.OnClickListener listener,int id){
        iv_right_view.setVisibility(View.VISIBLE);
        iv_right_view.setOnClickListener(listener);
        iv_right_view.setImageResource(id);
    }
    public void addBtnRigLhtistener(View.OnClickListener listener){
        id_tv_back.setVisibility(View.VISIBLE);
        id_tv_back.setOnClickListener(listener);
    }
    public void addBtnRightListener(View.OnClickListener listener,String title){
        tv_main_title_setting.setVisibility(View.VISIBLE);
        tv_main_title_setting.setOnClickListener(listener);
        tv_main_title_setting.setText(title);
    }


    //左边图片显示
    public void Left_Image() {

        iv_left_view.setVisibility(View.VISIBLE);
    }
    //左边textview
    public void Left_Text()
    {
        id_tv_back.setVisibility(View.VISIBLE);
    }


    //右边图片显示
    public void Right_Image()
    {
        iv_right_view.setVisibility(View.VISIBLE);
    }
    //右边textview
    public void Right_Text(){

        tv_main_title_setting.setVisibility(View.VISIBLE);
    }
    //头布局移仓方法
    public void SetGone(){

        id_tv_back.setVisibility(View.GONE);
        tv_main_title_setting.setVisibility(View.GONE);
        iv_right_view.setVisibility(View.GONE);
        iv_left_view.setVisibility(View.GONE);

    }
    //创建方法当处于某一标识时，调用显示方法
    public void setTitleStatue(int statue) {
        switch (statue){
            case LEFT_IMAEG_RIGHT_IMAGE:
                Left_Image();
                Right_Image();
                break;
            case LEFT_IMAGE_RIGHT_NO:
                Left_Image();
                SetGone();
                break;
            case LEFT_IMAGE_RIGHT_TEXT:
                Left_Image();
                Left_Text();
                Right_Text();
                break;
            case LEFT_NO_RIGHT_IMAGE:
                SetGone();
                Right_Image();
                break;
            case LEFT_NO_RIGHT_NO:
                SetGone();
                break;
            case LEFT_NO_RIGHT_TEXT:
                SetGone();
                Right_Text();
                break;
            case LEFT_TEXT_RIGHT_IMAGE:
                Left_Text();
                Right_Image();
                break;
            case LEFT_TEXT_RIGHT_NO:
                Left_Text();
                SetGone();
                break;
            case LEFT_TEXT_RIGHT_TEXT:
                Left_Text();
                Right_Text();
                break;
        }


    }

    @Override
    public void onClick(View view) {

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//                menu = getSlidingMenu();
        setBehindContentView(R.layout.activity_right);
//        menu.setMode(SlidingMenu.RIGHT);
//        menu.setFadeDegree(0.2f);
//        menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
//        menu.setBehindOffset(150);
//         im= (Image) findViewById(R.id.image);
//        //处理图片
//        Bitmap bitmap= BitmapFactory.decodeResource(getResources(),R.mipmap.photo);
//        im.setImageBitmap(bitmap);
    }
}
